/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.ui;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.geom.Point2D;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

import who.tmap.bo.Attrs;
import who.tmap.toolkit.impl.CartographicDisplayHelper;

/**
 * @author stl
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class JDialogCDPointSymbolInfo extends JDialog {

	private Attrs data;
	private Point2D pt;
    
	private javax.swing.JPanel jContentPane = null;

	private JPanel jPanelFields = null;
	private JButton jButtonClose = null;
	private JLabel jLabelX = null;
	private JLabel jLabelY = null;
	private JLabel jLabelXVal = null;
	private JLabel jLabelYVal = null;
	private JPanel jPanelButtons = null;
	private JCheckBox jCheckBoxRescale = null;
	private JLabel jLabelDesc = null;
	private JLabel jLabelDescVal = null;
	/**
	 * This is the default constructor
	 */
	public JDialogCDPointSymbolInfo( Frame parent, boolean modal, Attrs data, Point2D pt ) {
		super( parent, modal );
		this.data =data;
		this.pt =pt;
		initialize();
	}
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setTitle("Cartographic display point information");
		this.setSize(380,160);
		this.setContentPane(getJContentPane());
		this.setLocationRelativeTo( null );
		
		getRootPane().setDefaultButton( getJButtonOK() );
		
		processPointInfo();
	}
	
	private void processPointInfo() {
		jLabelXVal.setText( Double.toString( pt.getX() ) );
		jLabelYVal.setText( Double.toString( -pt.getY() ) );
		
//		if ( data != null && data.getXColumnIdx() != -1 
//				          && data.getYColumnIdx() != -1 && data.getDescriptorColumnIdx() != -1 ) {
//			List<List> rows =data.getRows();
//			if ( rows != null ) {
//				for( List row : rows ) {
//					if ( ( pt.getX() == (Double)row.get( data.getXColumnIdx() ) ) 
//					  && ( -pt.getY() == (Double)row.get( data.getYColumnIdx() ) ) ) {
//						jLabelDescVal.setText( (String)row.get( data.getDescriptorColumnIdx() ) );
//						break;
//					}
//				}
//			}
//		}
		jLabelDescVal.setText( new CartographicDisplayHelper().getDescForCDPoint( pt, data ) );
	}
	
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private javax.swing.JPanel getJContentPane() {
		if(jContentPane == null) {

			GridLayout gridLayout1 = new GridLayout();
			jContentPane = new javax.swing.JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(5,5,5,5));		
			jContentPane.add(getJPanelFields(), BorderLayout.NORTH);
			jContentPane.add(getJPanelButtons(), BorderLayout.SOUTH);
		}
		return jContentPane;
	}
	
	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanelFields() {
		if (jPanelFields == null) {

			jPanelFields = new JPanel();
			GridLayout gridLayout3 = new GridLayout(3,2);
			
			jPanelFields.setLayout(gridLayout3);		    
		    
			jLabelX = new JLabel();
			jLabelX.setText("X");
			jLabelXVal = new JLabel();			
			jLabelXVal.setText("");
			jLabelY = new JLabel();
			jLabelY.setText("Y");
			jLabelYVal = new JLabel();
			jLabelYVal.setText("");
			jLabelDesc = new JLabel();
			jLabelDesc.setText("Description");
			jLabelDescVal = new JLabel();
			jLabelDescVal.setText("");			
			
			jPanelFields.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,5,0));
			
			jPanelFields.add(jLabelX, null);
			jPanelFields.add(jLabelXVal, null);			
			jPanelFields.add(jLabelY, null);
			jPanelFields.add(jLabelYVal, null);
			jPanelFields.add(jLabelDesc, null);
			jPanelFields.add(jLabelDescVal, null);
		}
		return jPanelFields;
	}
	
	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */    
	private JButton getJButtonOK() {
		if (jButtonClose == null) {
			jButtonClose = new JButton();
			jButtonClose.setText("Close");
			
			jButtonClose.addActionListener(new java.awt.event.ActionListener() { 
				public void actionPerformed(java.awt.event.ActionEvent e) {    
				    dispose();
				}
			});
		}

		return jButtonClose;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanelButtons() {
		if (jPanelButtons == null) {
			jPanelButtons = new JPanel();

			jPanelButtons.add(getJButtonOK(), null);
		}
		return jPanelButtons;
	}

  }
